package flux;

import reactor.core.publisher.Flux;

import java.time.Duration;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

public class FluxDemo02 {
    public static void main(String[] args) {
        Flux<Integer> flux = Flux.range(1, 10000);
        Flux<Integer> flux2 = Flux.range(3000, 5000000);
        List<Integer> list = flux.filter(item -> item % 2 == 1)
                .map(item -> item * 10)
                .sort()
                .collect(Collectors.toList())
                .block();
//        list.stream().forEach(System.out::println);
        Flux.fromIterable(list).subscribe(System.out::println);
//                .subscribe(System.out::println);
      Flux flux3=  Flux.create(sink->{
           while (true){
               sink.next(System.currentTimeMillis());
               try {
                   TimeUnit.SECONDS.sleep(1);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
        });
//        flux3.zipWith(flux)
////                .sample(Duration.ofMillis(400))
//                .subscribe(System.out::println);

        flux
                .zipWith(flux2,(a,b)->a+"\t:"+b)
                .subscribe(System.out::println);

    }
}
